/**
 * 
 */
package hu.gbalage.owlforms.internal.derived;

import java.net.URI;

import hu.gbalage.owlforms.api.Field;
import hu.gbalage.owlforms.api.data.FormData;

/**
 * @author balage
 *
 */
public class EgyForeEsoJovedelemCalc implements IDerivedCalculator {

	public static final URI datapropt = URI.create("http://owlforms.gbalage.hu/example/egyforeesojovedelem.owl#hasEgyForeEsoJovedelem");
	
	protected int getValue(int data){
		if (data <= 21000) return 63;
		
		return 63-((data-21000)/1500)*2;
	}
	
	/* (non-Javadoc)
	 * @see hu.gbalage.owlforms.internal.derived.IDerivedCalculator#calculate(hu.gbalage.owlforms.api.data.FormData, hu.gbalage.owlforms.api.Field)
	 */
	public String calculate(FormData on, Field field) {
		String value = on.getData(on.getForm().getField(datapropt)).listValues().get(0).asPrimitiveValue().getValue();
		
		try{
			int d = Integer.parseInt(value);
			int szoc = getValue(d);
			return szoc+"";
		}catch(NumberFormatException e){
			e.printStackTrace();
		}
		
		return null;
	}

}
